<?php

namespace app\api\controller;

use app\admin\model\Announce;
use app\admin\model\Banner;
use app\admin\model\Help;
use app\admin\model\About;
use app\admin\model\News;
use app\admin\model\NewsCate;
use app\admin\model\Diamond;
use app\common\controller\Api;
use think\Env;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['index','HelpDetails','newscates','helpDetailss','Newcates'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $arr =[
            'banner'=>$this->banner(),//轮播
            'diamond'=>$this->diamond(),//金刚区模块名
            'aboutUs'=>$this->aboutUs(),//金刚区关于我们
            'announce'=>$this->announce(),//公告
            'newsCate'=>$this->newsCate(),//行业资讯分类
            'news'=>$this->news(),//行业资讯

        ];

        return sucessMsg(200,'获取成功',$arr);
    }
    public function banner ()
    {
        $modol = new Banner();
        $list  = $modol
            ->field('id,image')
            ->select();
        $list = addWebSiteUrl($list,['image']);
        return $list;
    }
    //金刚区模块名
    public function diamond()
    {
        $modul = new Diamond();
        $list = $modul
            ->where('type',1)
            ->field('id,title,image')
            ->select();
        $list = addWebSiteUrl($list,['image']);
        return $list;
    }
    //金刚区
    public function aboutUs()
    {
        $modul = new About();
        //关于我们
        $list = $modul
            ->where('type',1)
            ->field('id,content')
            ->select();
        //在线客服
        $list1 = $modul
            ->where('type',2)
            ->field('id,content')
            ->select();
        //玩法介绍
        $modul = new Help();
        $list2 = $modul
            ->field('id,title,create_time,image')
            ->select();
        //新人帮助
        $list3 = $modul
            ->field('id,title,create_time,image')
            ->select();
        return ['list' => $list, 'list1' => $list1, 'list2' => $list2, 'list3' => $list3] ;
    }
    //公告
    public function  announce()
    {
        $modul = new Announce();
        //首页标题
        $list = $modul
            ->field('id,title')
            ->select();
        //公告列表
        $list1 = $modul
            ->field('id,title,create_time,image')
            ->select();
        return ['list'=>$list,'list1'=>$list1];

    }
    //首页积分兑换

    //行业资讯分类
    public function newsCate()
    {
        $modul = new NewsCate();
        $list = $modul
            ->field('id,title')
            ->select();
        return $list;
    }

    //行业资讯
    public function news()
    {
        $cate_id = input('news_cate_id');
        $production = News::where('news_cate_id', $cate_id)
            ->field('id,image,title,create_time,news_cate_id')
            ->select();
        $list = addWebSiteUrl($production, ['image']);
        return $list;
    }
    //首页公告列表详情
    //首页玩法介绍详情页
    public function HelpDetails()
    {
        $id = input('id');
        if (empty($id)) {
            return errMsg(422,'请输入玩法介绍id');
        }
        $model = new Help();
        $list = $model
            ->where('id',$id)
            ->field('id,title,content,create_time')
            ->find();
        //$list->image = Env::get('database.yuming') . $list->image;
        return sucessMsg(200,'请求成功',$list);
    }
    //首页新人帮助详情页
    public function helpDetailss()
    {
        $id = input('id');
        if(empty($id)){
            return errMsg(422,'请输入新人帮助id！');
        }
        $model = new Help();
        $list = $model
            ->where('id',$id)
            ->field('id,title,content,create_time')
            ->find();
        //$list->image = Env::get('database.yuming') . $list->image;
        return sucessMsg(200,'请求成功',$list);
    }
    //首页积分兑换详情页
    //首页行业资讯详情页
    public function newscates()
    {
        $id = input('id');
        if(empty($id)){
            return errMsg(422,'请输入行业资讯id');
        }
        $model = new NewsCate();
        $list = $model
            ->where('id',$id)
            ->field('id,title')
            ->find();
        //$list->image = Env::get('database.yuming') . $list->image;
        return sucessMsg(200,'请求成功',$list);
    }
    //首页活动专区详情页
    public function Newcates()
    {
        $id = input('id');
        if(empty($id)){
            return errMsg(422,'请输入活动专区id！');
        }
        $model = new NewsCate();
        $list = $model
            ->where('id',$id)
            ->field('id,title')
            ->find();
        //$list->image = Env::get('database.yuming') . $list->image;
        return sucessMsg(200,'请求成功',$list);

    }

}






















